package com.ck.ips.controller.sys;

import com.ck.common.model.User;
import com.ck.core.annotation.LoginRequired;
import com.ck.core.annotation.SysLog;
import com.ck.core.constant.ModuleConstant;
import com.ck.core.constant.UserType;
import com.ck.ips.controller.BaseController;
import com.ck.ips.service.sys.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* @Description: 用户controller
* @Author: hf
* @Date:    2019/4/30 17:32
* @Version: 1.0
*/
@LoginRequired
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {
	private static Logger logger = LoggerFactory.getLogger(UserController.class);
	@Autowired
	private UserService userService;

	/**
	 * 保存用戶
	 */
	@SysLog(module = ModuleConstant.MODULE_USER)
	@PostMapping(value = "/save")
	public Object saveUser(String roleIds, Long departmentId, String userName, String realName, String password, String mobilePhone, Boolean status, String nickName, String avatar, String gender, String remark) {
		User user = new User();
		user.setDepartmentId(departmentId);
		user.setUserName(userName);
		user.setRealName(realName);
		user.setPassword(password);
		user.setMobilePhone(mobilePhone);
		user.setStatus(status);
		user.setNickName(nickName);
		user.setAvatar(avatar);
		user.setGender(gender);
		user.setRemark(remark);
		return userService.insertUser(user, UserType.NORMAL,roleIds);
	}

	/**
	 * 修改用户
	 */
	@SysLog(module = ModuleConstant.MODULE_USER)
	@PostMapping(value = "/update")
	public Object updateUser(String roleIds,Long userId, Long departmentId, String userName, String realName, String password, String mobilePhone, Boolean status, String nickName, String avatar, String gender, String remark) {
		User user = new User();
		user.setUserId(userId);
		user.setDepartmentId(departmentId);
		user.setRealName(realName);
		user.setMobilePhone(mobilePhone);
		user.setStatus(status);
		user.setNickName(nickName);
		user.setAvatar(avatar);
		user.setGender(gender);
		user.setRemark(remark);
		return userService.updateUser(user,roleIds);
	}

	/**
	 * 删除用户
	 */
	@SysLog(module = ModuleConstant.MODULE_USER)
	@PostMapping(value = "/delete")
	public Object deleteUser( Long userId ) {
		return userService.deleteUser(userId);
	}
	/**
	 * 用户列表
	 */
	@PostMapping(value = "/list")
	public Object listUser(Integer status, String userName,String realName,String mobile, Long departmentId,String roleName,Integer pageNum, Integer pageSize) {
		return userService.listUser( status, userName,realName,mobile,departmentId,roleName,pageNum, pageSize);
	}

	/**
	 * 启用禁用用户
	 */
	@SysLog(module = ModuleConstant.MODULE_USER)
	@PostMapping(value = "/enableDisableUser")
	public Object enableDisableUser(Long userId,Boolean status) {
		return userService.enableDisableUser(userId,status);
	}

	/**
	 * 重置密码
	 */
	@SysLog(module = ModuleConstant.MODULE_USER)
	@PostMapping(value = "/resetPassword")
	public Object resetPassword(Long userId, String password) {
		return 	userService.resetPassword(userId, password);
	}

}
